package org.korecky.gnotedigitalorganizer.components;

import java.awt.Component;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import org.korecky.gnotedigitalorganizer.MainWindow;

public class FileTreeCellRenderer extends DefaultTreeCellRenderer {
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
	super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

	if (value instanceof DefaultMutableTreeNode) {
	    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
	    if (node.getUserObject() instanceof File) {
		File file = (File) node.getUserObject();

		if (file.isDirectory())
		    setIcon(new ImageIcon(MainWindow.class.getResource("resources/icons16x16/folder.png")));
		else
		    setIcon(new ImageIcon(MainWindow.class.getResource("resources/icons16x16/office-document.png")));

		setText(file.getName());
	    }
	}
	return this;
    }
}
